﻿using System;
using System.IO;

namespace Sirian.Serialization
{
    public class LogWriter
    {
        private string logPath;
        public LogWriter(string logPath)
        {
            this.logPath = logPath;
        }

        public bool writeError(string errorMessage) 
        {
            bool success = false;
            TextWriter writer = null;
            try
            {
                writer = new StreamWriter(logPath, true);
                writer.WriteLine(DateTime.Now + " " + errorMessage);
                writer.Close();
                success = true;
            }
            catch (Exception ex)
            {
                if(writer != null) writer.Close();
                System.Console.Write(ex.Message);
            }
            return success;
        }
    }
}
